﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace DA_CLIENT.Controls
{
    public partial class ControlContact : UserControl
    {
        public ControlContact()
        {
            InitializeComponent();
            pictureBox1.Image = imageList1.Images[0];
        }
        private string contact; // username
        // Get Username để thao tác
        public string Contact
        {
            get
            {
                return contact;
            }
            set
            {
                contact = value;
            }
        }
        //Lấy tên đầy đủ để hiển thị lên Contact
        public string DisplayFullName {
            get {
                return lblContact.Text;
            }
            set {
                lblContact.Text = value;
            }
        }
        public bool online;
        public bool Online
        {
            get
            {
                return online;
            }
            set
            {
                online = value;
                if (value)
                {
                    pictureBox1.Image = imageList1.Images[1];
                }
                else
                {
                    pictureBox1.Image = imageList1.Images[0];
                }
                pictureBox1.Update();
                pictureBox1.Refresh();
            }
        }
        
        private void ControlContact_Load(object sender, EventArgs e)
        {
            
        }

        private void lblContact_Hover(object sender, EventArgs e)
        {
            lblContact.ForeColor = System.Drawing.Color.Red;
            lblContact.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        }

        private void lblContact_Leave(object sender, EventArgs e)
        {
            lblContact.ForeColor = System.Drawing.Color.Purple;
            lblContact.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_MouseHover(object sender, EventArgs e)
        {

        }

        public void Contact_Click(object sender, EventArgs e)
        {
            OpenFormMessenger(((ControlContact)sender).Contact);
        }

        private void OpenFormMessenger(string contact)
        {
            if (Global.windowList.Contains(contact))
            {
                ((FrmMessenger)Global.windowList[contact]).Focus();
            }
            else
            {
                FrmMessenger frmMessenger = new FrmMessenger();
                frmMessenger.contact = contact;
                frmMessenger.Text = Global.server.GetFullName(contact) + " (" + contact + ")" + " - Tin nhắn trực tiếp.";
                frmMessenger.Show();
                Global.windowList.Add(contact, frmMessenger);
            }
        }

        private void txtContact_Click(object sender, EventArgs e)
        {
            this.OnDoubleClick(new EventArgs());
        }
       
    }
}
